<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .active {
        color: red;
      }
    </style>
  </head>

  <body>
    <div id="app"></div>
    <template id="pengfan">
      <div :class="className">哈哈哈</div>
      <!-- 对象语法：{'active': boolean} -->
      <div :class="{'active': isActive}">呵呵呵</div>
      <button @click="toggle">切换</button>

      <!-- 也可以有多个键值对 -->
      <div :class="{'active': isActive,title: true}"></div>

      <!-- 默认的class和动态的class结合 -->
      <div class="abc cba" :class="{'active': isActive,title: true}"></div>

      <!-- 将对象放到一个单独的属性中 -->
      <div :class="classObj">呵呵呵呵</div>

      <!-- 将返回的对象放到一个methods(computed)方法中 -->
      <div :class=getClassObj()>hahahha</div>
    </template>
    <script src="../js/vue.js"></script>
    <script>
      Vue.createApp({
        template: "#pengfan",
        data() {
          return {
            message: "Hello World",
            className: "pengfan",
            isActive: true,
            classObj: {
                active: true,
                title: true
            }
          };
        },
        methods: {
          toggle() {
            this.isActive = !this.isActive;
          },
          getClassObj(){
              return {
                active: this.isActive,
                title: true
              }
          }
          
        },
      }).mount("#app");
    </script>
  </body>
</html>
